﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LibNiconico.NiconicoApi.Internal;
using LibNiconico.NiconicoApi.Extentions;
using System.IO;

namespace LibNiconico.NiconicoApi.Lives.Comments.Broadcast
{
    /// <summary>
    /// ニコニコ生放送問い合わせ情報
    /// </summary>
    public sealed class NicoLiveBroadcastQueryInfo:NicoUrlEncodedPostAble
    {
        /// <summary>
        /// 本文
        /// </summary>
        public string Body { get; set; }

        /// <summary>
        /// メールコマンドリスト
        /// </summary>
        public ICollection<string> Mails { get;  set; }

        /// <summary>
        /// トークン
        /// </summary>
        public string Token { get; set; }

        /// <summary>
        /// 匿名ユーザフラグの取得・設定
        /// </summary>
        public bool Is184 { get; set; }

        /// <summary>
        /// 対象の生放送番号
        /// </summary>
        public string LiveId { get; set; }

        /// <summary>
        /// コンストラクタ
        /// </summary>
        public NicoLiveBroadcastQueryInfo()
        {
            this.Body = "";
            this.Mails = new List<string>();
            this.Token = "";
            this.Is184 = true;
        }


        /// <summary>
        /// URLパス部分文字列として出力
        /// </summary>
        /// <returns></returns>
        internal override string AsPath()
        {
            return "api/broadcast/" + LiveId;
        }

        /// <summary>
        /// URL問い合わせ文字列として出力
        /// </summary>
        /// <returns></returns>
        internal override string AsQuery()
        {
            return "";
        }

        /// <summary>
        /// ポスト用データとして出力
        /// </summary>
        /// <returns></returns>
        internal override byte[] AsPostData()
        {
            MemoryStream stream = new MemoryStream();
            QueryStrings query = new QueryStrings();
            query.Add("token", this.Token);
            query.Add("body", this.Body);
            query.Add("mail", string.Join(" ", this.Mails));
            query.Add("is184", this.Is184 ? "true" : "false");
            using (StreamWriter writer = new StreamWriter(stream))
            {
                 writer.Write(query.ToString());
            }

            return stream.ToArray();

            
            
        }
    }
}
